import { Navigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { selectAuth } from '@/store';

export default function LoginGuard({ children }) {
  const { isAuthenticated,user } = useSelector(selectAuth);

  if (isAuthenticated&&user) {
    // 已登录时重定向到首页
    return <Navigate to="/" replace />;
  }

  return children;
}